<template>
  <div class="building-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <div class="search-label">一体杆名称：</div>
      <el-input v-model="params.poleName" placeholder="一体杆名称" class="search-main" />
      <div class="search-label">一体杆编号：</div>
      <el-input v-model="params.poleNumber" placeholder="一体杆编号" class="search-main" />
      <div class="search-label">处置状态：</div>
      <el-select v-model="params.poleStatus" placeholder="请选择">
        <el-option label="全部" value="" />
        <el-option label="正常" value="1" />
        <el-option label="异常" value="0" />
      </el-select>
      <el-button type="primary" class="checkbtn" @click="getoneList">查询</el-button>
    </div>
    <div class="create-container">
      <el-button type="primary" @click="opendialog">添加一体杆</el-button>
      <el-button @click="delAll">批量删除</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table
        ref="table"
        style="width: 100%"
        :data="list"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
        />
        <el-table-column type="index" label="序号" width="80" />
        <el-table-column label="一体杆名称" width="180" prop="poleName" />
        <el-table-column label="一体杆编号" prop="poleNumber" width="180" />
        <el-table-column label="一体杆IP" width="180" prop="poleIp" />
        <el-table-column label="安装区域" width="120" prop="areaName" />
        <el-table-column label="一体杆类型" width="120" prop="poleType">
          <template #default="scope">
            {{ formatType(scope.row.poleType) }}
          </template>
        </el-table-column>
        <el-table-column label="运行状态" width="120" prop="poleStatus">
          <template #default="scope">
            {{ formatStatus(scope.row.poleStatus) }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button size="mini" type="text" @click.native="editlone(scope.row.poleName)">编辑</el-button>
            <el-button size="mini" type="text" @click.native="delone(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      background
      layout="prev, pager, next,total"
      :total="total"
      @current-change="changepage"
    />
    <ADD
      ref="addMoudle"
      :addlog-visible="addlogVisible"
      @close="closedialog"
      @randerList="getoneList"
    />
  </div>
</template>

<script>
import { getListAPI, delListAPI } from '@/api/one'
import ADD from '@/views/Rod/RodManage/add.vue'
export default {
  name: 'Rodmanage',
  components: {
    ADD
  },
  data() {
    return {
      params: {
        page: 1,
        pageSize: 5,
        poleName: '',
        poleNumber: '',
        poleStatus: ''
      },
      list: [],
      addlogVisible: false,
      total: 0,
      idArr: ''
    }
  },
  created() {
    this.getoneList()
  },
  methods: {
    // 初始化
    async getoneList() {
      const res = await getListAPI(this.params)
      this.list = res.data.rows
      this.total = res.data.total
    },
    // 枚举
    formatType(value) {
      const Map = {
        export: '出口',
        entrance: '入口'
      }
      return Map[value]
    },
    formatStatus(value) {
      const Map = {
        0: '异常',
        1: '正常'
      }
      return Map[value]
    },
    // 单独删除
    delone(id) {
      this.$confirm('确定删除吗', '警告').then(async() => {
        await delListAPI(id)
        this.getoneList()
        this.$message.success('删除成功')
      }).catch()
    },
    // 编辑
    editlone(value) {
      this.$refs.addMoudle.editCommand(value)
      this.addlogVisible = true
    },
    // dialog的开关
    closedialog() {
      this.addlogVisible = false
    },
    opendialog() {
      this.addlogVisible = true
    },
    // 分页器
    changepage(page) {
      this.params.page = page
      this.getoneList()
    },
    // 批量删除
    handleSelectionChange(value) {
      this.idArr = value.map(item => item.id).join(',')
    },
    delAll() {
      this.$confirm('确定删除吗', '警告').then(async() => {
        await delListAPI(this.idArr)
        this.getoneList()
        this.$message.success('批量删除成功')
      }).catch()
    }
  }
}

</script>

<style lang="scss" scoped>
.department-container {
  padding: 10px;
}
.create-container{
  margin: 20px 0px;
}
.checkbtn{
margin-left: 10px;
}
.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, 0.9);
  padding-bottom: 20px;
  .search-label {
    width: 100px;
  }
  .search-main {
    width: 220px;
    margin-right: 10px;
  }
  .page-container {
    padding: 4px 0px;
    text-align: right;
  }

}
</style>
